package com.dm.cloud.images.controller;

import com.dm.cloud.core.mode.ResultModel;
import com.dm.cloud.images.mode.VolumeCreateRequest;
import com.dm.cloud.images.mode.VolumeDetail;
import com.dm.cloud.images.service.VolumesService;
import com.dm.cloud.oauthlib.service.anon.HasLogin;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/apis/v1/volume")
@Tag(name = "数据卷管理")
@HasLogin
public class VolumesController {

    @Autowired
    private VolumesService volumesService;

    @PostMapping("create")
    @Operation(summary = "创建数据卷")
    public ResultModel<VolumeDetail> create(@RequestBody VolumeCreateRequest volumeCreateRequest){
        VolumeDetail inspect = volumesService.create(volumeCreateRequest);
        return ResultModel.success(inspect);
    }

    @GetMapping("list")
    @Operation(summary = "数据卷列表")
    public ResultModel<List<VolumeDetail>> list(
            @Parameter(in = ParameterIn.QUERY,description = "名称查询") String name,
            @Parameter(description = "节点ID",in = ParameterIn.QUERY) String nodeId
    ){
        List<VolumeDetail> volumes=volumesService.list(name,nodeId);
        return ResultModel.success(volumes);
    }

    @DeleteMapping("delete")
    @Operation(summary = "删除数据卷")
    public ResultModel<Boolean> delete(
            @Parameter(in = ParameterIn.QUERY,description = "数据卷名称") String name
            ,@Parameter(in = ParameterIn.QUERY,description = "节点ID") String nodeId
    ){
        return ResultModel.success(volumesService.delete(nodeId,name));
    }

}
